import tkinter
import tkinter.messagebox
import random
import threading
import itertools
import time

root=tkinter.Tk()
root.title("随机提问")
root.geometry('260x180+400+300')
root.resizable(False,False)

def closeWindow():
    root.flag=False
    time.sleep(0.1)
    root.destroy()
root.protocol('WM_DELETE_WINDOW',closeWindow) 

students=['张三','李四','贺立上','王五','赵六','孙七','周八','吴九','郑十']
root.flag=False

def switch():
    root.flag=True
    t=students[:]
    random.shuffle(t)
    t=itertools.cycle(t)

    while root.flag:
        IbFirst['text']=IbSecond['text']
        IbSecond['text']=IbThird['text']
        IbThird['text']=next(t)

        time.sleep(0.1)

def btnStartClick():
    t=threading.Thread(target=switch)
    t.start()
    btnStart['state']='disabled'
    btnStop['state']='normal'
btnStart=tkinter.Button(root,text='开始',command=btnStartClick)
btnStart.place(x=30,y=20,width=80,height=20)

def btnStopClick():
    root.flag=False
    time.sleep(0.3)
    tkinter.messagebox.showinfo('恭喜','本次中奖：'+IbThird['text'])
    btnStart['state']='normal'  
    btnStop['state']='disabled'
btnStop=tkinter.Button(root,text='停止',command=btnStopClick) 
btnStop['state']='disabled'
btnStop.place(x=150,y=10,width=80,height=20)

IbFirst=tkinter.Label(root,text='')
IbFirst.place(x=80,y=60,width=100,height=20)

IbSecond=tkinter.Label(root,text='')
IbSecond['fg']='red'
IbSecond.place(x=80,y=90,width=100,height=20)

IbThird=tkinter.Label(root,text='')
IbThird.place(x=80,y=120,width=100,height=20)

root.mainloop()